package com.jtjrenren.android.taxi.driver.core.dutyon;

import com.jtjrenren.android.taxi.driver.bean.api.ApiDriverSr;
import com.jtjrenren.android.taxi.driver.bean.api.ApiOrderNotFinish;
import com.jtjrenren.android.taxi.driver.bean.api.ApiCommonResult;
import com.jtjrenren.android.taxi.driver.bean.api.ApiYYD;
import com.jtjrenren.android.taxi.driver.bean.event.DriverIncomeEvent;
import com.jtjrenren.android.taxi.driver.bean.event.OrderNotFinishEvent;
import com.jtjrenren.android.taxi.driver.bean.event.YydListEvent;
import com.jtjrenren.android.taxi.driver.manger.api.ApiWorks;
import com.jtjrenren.android.taxi.driver.utils.GsonUtils;


import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by Administrator on 2016/8/26.
 */

public class DutyOnInterctorImpl implements DutyOnInterctor {
    @Override
    public void getNotFinishOrder(String carNo, String driverID) {
        ApiWorks.getOrderNotFinish(carNo, driverID, new ApiWorks.ResponseListener<ApiCommonResult>() {
            @Override
            public void onResponse(ApiCommonResult apiCommonResult) {
                if (apiCommonResult != null && apiCommonResult.getCode() == 1) {//有未完成订单，进行下一步操作
                    List<ApiOrderNotFinish> apiOrderNotFinishs = GsonUtils.fromJsonArray(apiCommonResult.getData(), ApiOrderNotFinish.class);
                    if (apiOrderNotFinishs != null && apiOrderNotFinishs.size() > 0) {
                        EventBus.getDefault().post(new OrderNotFinishEvent(apiOrderNotFinishs.get(0).getID()));
                    }
                }
            }
        });
    }

    @Override
    public void refreshJtsr(String driverID) {
        ApiWorks.getTodaySr(driverID, new ApiWorks.ResponseListener<ApiDriverSr>() {
            @Override
            public void onResponse(ApiDriverSr apiDriverSr) {
                EventBus.getDefault().post(new DriverIncomeEvent(apiDriverSr));
            }
        });
    }

    @Override
    public void getYyd(String driverID) {
        ApiWorks.getYYDList(driverID, new ApiWorks.ResponseListener<List<ApiYYD>>() {
            @Override
            public void onResponse(List<ApiYYD> apiYYDs) {
                EventBus.getDefault().post(new YydListEvent(apiYYDs));
            }
        });
    }

    @Override
    public void getSjQdCount(String driverID) {

    }

}
